public class TriangleTest {

	public static boolean testScaleneRight() {
		Triangle t[] = new Triangle[2];

		t[0] = new Triangle(3, 4, 5);
		t[1] = new Triangle(4, 3, 5);

		for (int i=0; i<2; i++) {
			if (!(t[i].triangleType().equals("scalene")))
				return false;
			if (!(t[i].isRightTriangle()))
				return false;
		}

		return true;
	}

	public static boolean testScaleneNonRight() {
		Triangle t[] = new Triangle[6];

		t[0] = new Triangle(3, 4, 6);
		t[1] = new Triangle(3, 6, 4);
		t[2] = new Triangle(4, 3, 6);
		t[3] = new Triangle(4, 6, 3);
		t[4] = new Triangle(6, 3, 4);
		t[5] = new Triangle(6, 4, 3);

		for (int i=0; i<6; i++) {
			if (!(t[i].triangleType().equals("scalene")))
				return false;
			if (t[i].isRightTriangle())
				return false;
		}

		return true;
	}

	public static boolean testIsoscelesRight() {
		Triangle t[] = new Triangle[2];

		t[0] = new Triangle(Math.sqrt(2), Math.sqrt(2), 2.0);
		t[1] = new Triangle(1.0, 1.0, Math.sqrt(2));

		for (int i=0; i<2; i++) {
			if (!(t[i].triangleType().equals("isosceles")))
				return false;
			if (!(t[i].isRightTriangle()))
				return false;
		}

		return true;
	}

	public static boolean testIsoscelesNonRight() {
		Triangle t[] = new Triangle[3];

		t[0] = new Triangle(3, 4, 4);
		t[1] = new Triangle(4, 4, 3);
		t[2] = new Triangle(4, 3, 4);

		for (int i=0; i<3; i++) {
			if (!(t[i].triangleType().equals("isosceles")))
				return false;
			if (t[i].isRightTriangle())
				return false;
		}

		return true;
	}

	public static boolean testEquilateral() {
		Triangle t;

		t = new Triangle(3, 3, 3);

		if (!(t.triangleType().equals("equilateral")))
			return false;
		if (t.isRightTriangle())
			return false;

		return true;
	}	

	public static boolean testInvalid() {
		Triangle t[] = new Triangle[5];

		//invalid inputs
		t[0] = new Triangle(0, 1, 2);
		t[1] = new Triangle(1, 0, 2);
		t[2] = new Triangle(2, 1, 0);
		t[3] = new Triangle(-2, -3, -5);
		//impossible triangles (Inequality Theorem)
		t[4] = new Triangle(1, 2, 300);

		for (int i=0; i<5; i++) {
			if (!(t[i].triangleType().equals("invalid")))
				return false;
			if (t[i].isRightTriangle())
				return false;
		}

		return true;
	}

	public static boolean testInvalidEqualCase() {
		Triangle t = new Triangle(10, 20, 30);

		if (!(t.triangleType().equals("invalid")))
			return false;
		if (t.isRightTriangle())
			return false;

		return true;
	}

	public static boolean testRightTolerance() {
		Triangle t = new Triangle(10.1, 20.2, 22.584);

		if (!(t.triangleType().equals("scalene")))
			return false;
		if (!(t.isRightTriangle()))
			return false;

		return true;
	}

	public static boolean testLargeValueIsosceles() {
		Triangle t = new Triangle(1234567890000.0, 9876543210000.0, 9876543210000.0);

		if (!(t.triangleType().equals("isosceles")))
			return false;
		if (t.isRightTriangle())
			return false;

		return true;
	}
	
	public static void main(String[] args) {
		boolean success = true;
	
		if(!testScaleneRight()) {
			success = false;
			System.out.println("Failed scalene right test");
		}
		if(!testScaleneNonRight()) {
			success = false;
			System.out.println("Failed scalene non-right test");
		}
		if(!testIsoscelesRight()) {
			success = false;
			System.out.println("Failed isosceles right test");
		}
		if(!testIsoscelesNonRight()) {
			success = false;
			System.out.println("Failed isosceles non-right test");
		}
		if(!testEquilateral()) {
			success = false;
			System.out.println("Failed equilateral test");
		}
		if(!testInvalid()) {
			success = false;
			System.out.println("Failed invalid triangle test");
		}
		if(!testInvalidEqualCase()) {
			success = false;
			System.out.println("Failed invalid equal side case test");
		}
		if(!testRightTolerance()) {
			success = false;
			System.out.println("Failed right triangle precision tolerance test");
		}
		if(!testLargeValueIsosceles()) {
			success = false;
			System.out.println("Failed large side value isosceles test");
		}

		if (success)
			System.out.println("All tests succeeded.");
		else
			System.out.println("One or more tests failed.");
	}
}
